import { defineStore } from 'pinia';
import { store, usePermissionStore } from '@/store';
import { MessagePlugin } from 'tdesign-vue-next';
import { filterHTML } from '@/utils/minxin';
interface ExhibitListType {
  ageId?: number | null;
  ageIds?: string | null;
  ageValue?: string | null;
  browseTotal?: number | null;
  commentTotal?: number | null;
  companyId?: number | null;
  companyLogoUrl?: string | null;
  companyName?: string | null;
  concreteTimes?: string | null;
  coverUrl?: string | null;
  description?: any;
  followTotal?: number | null;
  id?: number | null;
  images?: [];
  isFollow?: boolean;
  isFollowCompany?: boolean;
  levelId?: number | null;
  levelValue?: string | null;
  likeTotal?: null | string | number;
  name?: string;
  next?: null | string | number;
  openStatus?: 1;
  prev?: null | string | number;
  size?: string | null;
  sourceId?: number | null;
  sourceValue?: string | null;
  texture?: string | null;
  typeId?: number | null;
  typeValue?: string | null;
}
export const ExhibitStore = defineStore('Exhibit', {
  state: () => ({
    ExhibitList: [],
  }),
  getters: {},
  actions: {
    pushExhibitInfo(e: any) {
      if (this.ExhibitList.length < 6) {
        let num = this.ExhibitList.findIndex((el) => {
          return el.id == e.id;
        });
        if (num == -1) {
          let arr = { ...e };
          if (e.description) {
            arr.description = filterHTML(e.description);
          }

          this.ExhibitList.push(arr);
        } else {
          MessagePlugin.warning('展品已存在对比列表');
        }
        if (this.ExhibitList.length == 6) {
          MessagePlugin.warning('对比展品添加已达上限');
        }
      }
    },
    deleteInfo(index: number) {
      this.ExhibitList.splice(index, 1);
    },
    removeList() {
      this.ExhibitList = [];
    },
    sortList(e: any) {
      this.ExhibitList = e;
    },
  },
  persist: true,
});
export function getExhibitStore() {
  return ExhibitStore(store);
}
